#include "MenuGamePlay.h"

MenuGamePlay::MenuGamePlay()
{
	_backGround=new CSprites("Images\\BackGroundMenu.png",400,400,1,1);
	_spriteChose=new CSprites("Images\\ChoseGameMenu.png",300,50,4,1);
	_chooseOption=0;
}
MenuGamePlay::~MenuGamePlay()
{
	delete _backGround;
	delete _spriteChose;
}
void MenuGamePlay::Render(int x, int y)
{
	_backGround->Render(x,y,0);
	_spriteChose->Render(x+50,y+50+(_chooseOption*70),_chooseOption);
}
void MenuGamePlay::Update(bool &pause,GameState &state,CMap *currentMap, LPDIRECT3DSURFACE9 & gr, SOUND *sound )
{
	CGameSate::_dxInput->Pool_Keyboard();
	
	if(CGameSate::_dxInput->OnKeyDown(DIK_UP))
	{
		_chooseOption--;
		if(_chooseOption<0)
			_chooseOption=3;
		CGameSate::_sound->Play("MenuChange",false);
	}
	if(CGameSate::_dxInput->OnKeyDown(DIK_DOWN))
	{
		_chooseOption=(_chooseOption+1)%4;
		CGameSate::_sound->Play("MenuChange",false);
	}

	if(CGameSate::_dxInput->OnKeyDown(DIK_RETURN))
	{
		switch(_chooseOption)
		{
		case 0://resume
			pause=false;
			return;

		case 1://load game
			delete currentMap;
			currentMap=new CMap(sound,4);
			if (currentMap->GetWorld()==2)
				gr=CGameSate::_gr->LoadSurface("Images\\BackGroundNight.png",D3DCOLOR_ARGB(255,0,0,0));
			else
				gr=CGameSate::_gr->LoadSurface("Images\\BackGroundDay.png",D3DCOLOR_ARGB(255,0,0,0));
			pause=false;
			return;
		case 2://save game
			currentMap->SaveDataToFile();
			pause=false;
			return;
		case 3://back to menu
			currentMap->Reset();
			currentMap->_infomation->Reset();
			pause=false;
			state=GameState::Menu;
			return;
		}

	}
}

void MenuGamePlay::Reset()
{
	_chooseOption=0;
}